from typing import override

import httpx

from async_worker import AsyncWorker


class MyWorker(AsyncWorker):
    API = 'http://127.0.0.1:8081/request'
    @override
    async def work(self, param:int):
        resp = await self.client.post(self.API, json={'seed':param})
        resp.raise_for_status()
        return resp.json()


if __name__ == '__main__':
    import random

    params = [random.randint(1,1000) for _ in range(1000)]
    client = httpx.AsyncClient()
    fp = 'store.json'
    myworker = MyWorker('MyTest', params, client=client, fp=fp, auto_resume=True)
    myworker.run_sync(chunk_size=200, fail_tol_rate=.1)
    